package com.ztomorrow.ying_cun_plus.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.ztomorrow.ying_cun_plus.constant.front.CacheConstant.CAFFEINE_BOOK_INFO_TTL;
import static com.ztomorrow.ying_cun_plus.constant.front.CacheConstant.CAFFEINE_HOME_BOOK_TTL;

@Configuration
public class CaffeineConfig {

    @Bean
    public Cache<String, List<Object>> caffeine() {
        return Caffeine.newBuilder()
                .expireAfterAccess(CAFFEINE_HOME_BOOK_TTL, TimeUnit.MINUTES)
                .build();
    }

    @Bean
    public <T> Cache<String, T> caffeineOne() {
        return Caffeine.newBuilder()
                .expireAfterAccess(CAFFEINE_BOOK_INFO_TTL, TimeUnit.MINUTES)
                .build();
    }
}
